package StudyCode.summary.Basic.stringbuilder;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class StringBuilderUsing {
	public static void main(String[] args) {
		// new 一个空的StringBuilder
		StringBuilder sb = new StringBuilder();
		printDetails(sb);

		// 追加 "World"
		sb.append("World");
		printDetails(sb);

		// 插入 "Hello  " 到开头
		sb.insert(0, "Hello  ");
		printDetails(sb);

		// 删除第六个字符
		sb.deleteCharAt(5);
		printDetails(sb);

		sb.append(" by java");
		printDetails(sb);

		// 设置长度为 3
		sb.setLength(3);
		printDetails(sb);

		// 对内容反向
		sb.reverse();
		printDetails(sb);
	}

	public static void printDetails(StringBuilder sb) {
		System.out.println("Content: \"" + sb + "\"");
		System.out.println("Length: " + sb.length());
		System.out.println("Capacity: " + sb.capacity());

		System.out.println();
	}
}
